19. Exercise: Add-RTL-Support
L10 33 RTL SC
1. In AndroidManifest.xml, add android:supportsRtl="true" to the <application>:
<application
android:supportsRtl="true">
2. Show a Right to Left preview of your layout.
In activity_main.xml, switch to the Design tab and select Preview Right to Left from the Locale for Preview dropdown.
3. Set your device to RTL.
In your device or emulator settings, select 'Force RTL layout direct in from Developer Options.
Run the app and verify main screen looks OK. Then navigate to the Search screen and see that it does not display correctly.
4. Add RTL support to the TextView.
In list_item.xml, edit the TextView, to support RTL by changing layout_constraintLeft_toLeftOf="parent" to layout_constraintStart_toStartOf="parent".
Run the app again and verify that the TextView looks better, but now the GDG icon reversed.
5. Change TextView to add RTL margin support.
In list_item.xml, replace the TextView's layout_marginLeft to layout_marginStart.
6. To fix the problem, we have to remove mirroring from the icon.
Open res/drawable/ic_gdg.xml and delete android:autoMirrored="true" from the first line of code.
Run the app again and open the Search GDG screen. The logo should be fixed now!
If you want to start at this step, you can download this exercise from: Step.08-Exercise-Add-RTL-Support.
You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck, go back and watch the video again.
Once you’re done, you can check your solution against the solution we’ve provided here: Step.08-Solution-Add-RTL-Support, or using this git diff.
Task Description:
Complete the tasks below to add Right-to-Left support.
Task Feedback:
Good work! Your app will work in almost any language now!
Reference documentation